<?php

require('config.php');

$provincesByUrl = modelProvince::getProvinceByUrl('provinces.php');
$balise_title = $provincesByUrl->title;
$description = $provincesByUrl->meta_title;

$id_menu_left_tree = modelProvince::getProvinceMenuleft($provincesByUrl->language_link)->id_menu_left_tree;

$page = new rootLayoutPage();
$menu = new layoutMenuLeft();
$menuPage = new layoutMenuPage();
$menuPage->setTable('province');
$menuPage->setIdShow($id_menu_left_tree);
$menu->setIdShow($id_menu_left_tree);
$menu->pushMenu($menuPage);
$page->setMenuPage($menu);
//--------Menu indicator--------------//
$menuIndictor = new layoutMenuIndicator();
$menuIndictor->idTree($id_menu_left_tree);
$menuIndictor->title($balise_title);
$page->setMenuIndicator($menuIndictor);

//************************//
/*$arr = array();
$getListUrlPage = modelPage::getListUrlPage($language_link);
foreach($getListUrlPage AS $key=>$Url){
	$arr[$Url->language_code]=$Url->url_rewriting.'-'.$Url->language_link.'.html';
}*/

$header = new layoutHeader();
//$header->setArrayUrl($arr);
$header->setIdShow($id_menu_left_tree);
$page->setHeader($header);

$page->setBaliseTitle($balise_title);
$page->setDescription($description);

$extension = filename_extension($_SERVER['REQUEST_URI']);
//if($extension == 'html') $page->setCanonical($html_name);

$Body = new flyLayout(REP_TPL . 'provinces.tpl');
$Body->start();
	$listProvinceAll = modelProvince::getList(1);
	$seper=0;
		if($listProvinceAll->size()>5) {
			for($i=1;$i<$listProvinceAll->size()/2;$i++){
				$all = $listProvinceAll->size();
				if($all-($i+$i)<=$i){ $seper = $i; break;}

			}
		}//die("size=>".$listProvinceAll->size()."|||seper=>".$seper);
	if($listProvinceAll->size() > 0){
		if($seper==0){
			$listProvince1  = modelProvince::getList(1);
			if($listProvince1->size() > 0){
				foreach($listProvince1 as $k1 => $province1){
					$urlProvince1 = LANGUAGE_FOLDER.'/'.$province1->url_rewriting.'-'.$province1->language_link.'.html';
					$language_link_1 = $province1->language_link;
					$listAllProvince_1 = modelProvince::getListProvinceByid($language_link_1);
					if($listAllProvince_1->size() > 0){
						$Body->setVariable('title_province_1',$province1->title);
						$Body->setVariable('url_province_1',$urlProvince1);
						$Body->showBlock('url_province_1_no_child');
						$Body->hideBlock('url_province_1_have_child');
					}else{
						$Body->setVariable('title_province_1',$province1->title);
						$Body->showBlock('url_province_1_have_child');
						$Body->hideBlock('url_province_1_no_child');
					}
					$Body->resetList('provinces_district_1');
						/*$listPDistrict1 = modelProvince::getProvinceDistrictByIDProvince($province1->language_link,1);
						if($listPDistrict1->size() > 0){
							foreach($listPDistrict1 as $kd1 => $province_district){							
								$url_province_district_1 = LANGUAGE_FOLDER.'/'.$province_district->url_rewriting.'-'.$province_district->language_link.'.html';
								$language_link_province_district_1 = $province_district->language_link;
								$listAllProvinceDistrict = modelDistrict::getListProvinceDistrictByid($language_link_province_district_1);
								if($listAllProvinceDistrict->size() > 0){
									$Body->setVariable('title_province_district_1',trim($province_district->title));
									$Body->setVariable('url_province_district_1',$url_province_district_1);
									$Body->showBlock('url_province_district_1_no_child');
									$Body->hideBlock('url_province_district_1_have_child');
								}else{
									$Body->setVariable('title_province_district_1',trim($province_district->title));
									$Body->showBlock('url_province_district_1_have_child');
									$Body->hideBlock('url_province_district_1_no_child');
								}
								$Body->parseList('provinces_district_1');
							}
							$Body->showBlock('provinces_d1');
						}else $Body->hideBlock('provinces_d1');*/

					$Body->parseList('provinces_1');
				}
			}
		}else{
			//$limit1 = "0,".$listProvinceAll->size()/2;
			$limit1 = "0,".$seper;
			$listProvince1  = modelProvince::getList(1,$limit1);
			if($listProvince1->size() > 0){
				foreach($listProvince1 as $k1 => $province1){
					$urlProvince1 = LANGUAGE_FOLDER.'/'.$province1->url_rewriting.'-'.$province1->language_link.'.html';
					$language_link_1 = $province1->language_link;
					$listAllProvince_1 = modelProvince::getListProvinceByid($language_link_1);
					if($listAllProvince_1->size() > 0){
						$Body->setVariable('title_province_1',$province1->title);
						$Body->setVariable('url_province_1',$urlProvince1);
						$Body->showBlock('url_province_1_no_child');
						$Body->hideBlock('url_province_1_have_child');
					}else{
						$Body->setVariable('title_province_1',$province1->title);
						$Body->showBlock('url_province_1_have_child');
						$Body->hideBlock('url_province_1_no_child');
					}
					$Body->resetList('provinces_district_1');
						/*$listPDistrict1 = modelProvince::getProvinceDistrictByIDProvince($province1->language_link,1);
						if($listPDistrict1->size() > 0){
							foreach($listPDistrict1 as $kd1 => $province_district){
								$url_province_district_1 = LANGUAGE_FOLDER.'/'.$province_district->url_rewriting.'-'.$province_district->language_link.'.html';
								$language_link_province_district_1 = $province_district->language_link;
								$listAllProvinceDistrict = modelDistrict::getListProvinceDistrictByid($language_link_province_district_1);
								if($listAllProvinceDistrict->size() > 0){
									$Body->setVariable('title_province_district_1',trim($province_district->title));
									$Body->setVariable('url_province_district_1',$url_province_district_1);
									$Body->showBlock('url_province_district_1_no_child');
									$Body->hideBlock('url_province_district_1_have_child');
								}else{
									$Body->setVariable('title_province_district_1',trim($province_district->title));
									$Body->showBlock('url_province_district_1_have_child');
									$Body->hideBlock('url_province_district_1_no_child');
								}
								$Body->parseList('provinces_district_1');
							}
							$Body->showBlock('provinces_d1');
						}else $Body->hideBlock('provinces_d1');*/

					$Body->parseList('provinces_1');
				}
			}
			//$limit2 = (($listProvinceAll->size()/2)+1).",".$listProvinceAll->size();
			$limit2 = ($seper+1).",".$seper;
			$listProvince2  = modelProvince::getList(1,$limit2);
			if($listProvince2->size() > 0){
				foreach($listProvince2 as $k2 => $province2){
					$urlProvince2 = LANGUAGE_FOLDER.'/'.$province2->url_rewriting.'-'.$province2->language_link.'.html';
					$language_link_2 = $province2->language_link;
					$listAllProvince_2 = modelProvince::getListProvinceByid($language_link_2);
					if($listAllProvince_2->size() > 0){
						$Body->setVariable('title_province_2',$province2->title);
						$Body->setVariable('url_province_2',$urlProvince2);
						$Body->showBlock('url_province_2_no_child');
						$Body->hideBlock('url_province_2_have_child');
					}else{
						$Body->setVariable('title_province_2',$province2->title);
						$Body->showBlock('url_province_2_have_child');
						$Body->hideBlock('url_province_2_no_child');
					}
					$Body->resetList('provinces_district_2');
						/*$listPDistrict2 = modelProvince::getProvinceDistrictByIDProvince($province2->language_link,1);
						if($listPDistrict2->size() > 0){
							foreach($listPDistrict2 as $kd2 => $province_district_2){
								$url_province_district_2 = LANGUAGE_FOLDER.'/'.$province_district_2->url_rewriting.'-'.$province_district_2->language_link.'.html';
								$language_link_province_district_2 = $province_district_2->language_link;
								$listAllProvinceDistrict_2 = modelDistrict::getListProvinceDistrictByid($language_link_province_district_2);
								if($listAllProvinceDistrict_2->size() > 0){
									$Body->setVariable('title_province_district_2',trim($province_district_2->title));
									$Body->setVariable('url_province_district_2',$url_province_district_2);
									$Body->showBlock('url_province_district_2_no_child');
									$Body->hideBlock('url_province_district_2_have_child');
								}else{
									$Body->setVariable('title_province_district_2',trim($province_district_2->title));
									$Body->showBlock('url_province_district_2_have_child');
									$Body->hideBlock('url_province_district_2_no_child');
								}
								$Body->parseList('provinces_district_2');
							}
							$Body->showBlock('provinces_d2');
						}else $Body->hideBlock('provinces_d2');*/
					$Body->parseList('provinces_2');
				}
			}
			$limit3 = ($seper+$seper+1).",".$seper;
			$listProvince3  = modelProvince::getList(1,$limit3);
			if($listProvince3->size() > 0){
				foreach($listProvince3 as $k3 => $province3){
					$urlProvince3 = LANGUAGE_FOLDER.'/'.$province3->url_rewriting.'-'.$province3->language_link.'.html';
					$language_link_3 = $province3->language_link;
					$listAllProvince_3 = modelProvince::getListProvinceByid($language_link_3);
					if($listAllProvince_3->size() > 0){
						$Body->setVariable('title_province_3',$province3->title);
						$Body->setVariable('url_province_3',$urlProvince3);
						$Body->showBlock('url_province_3_no_child');
						$Body->hideBlock('url_province_3_have_child');
					}else{
						$Body->setVariable('title_province_3',$province3->title);
						$Body->showBlock('url_province_3_have_child');
						$Body->hideBlock('url_province_3_no_child');
					}
					$Body->resetList('provinces_district_3');
						/*$listPDistrict3 = modelProvince::getProvinceDistrictByIDProvince($province3->language_link,1);
						if($listPDistrict3->size() > 0){
							foreach($listPDistrict3 as $kd3 => $province_district_3){
								$url_province_district_3 = LANGUAGE_FOLDER.'/'.$province_district_3->url_rewriting.'-'.$province_district_3->language_link.'.html';
								$language_link_province_district_3 = $province_district_3->language_link;
								$listAllProvinceDistrict_3 = modelDistrict::getListProvinceDistrictByid($language_link_province_district_3);
								if($listAllProvinceDistrict_3->size() > 0){
									$Body->setVariable('title_province_district_3',trim($province_district_3->title));
									$Body->setVariable('url_province_district_3',$url_province_district_3);
									$Body->showBlock('url_province_district_3_no_child');
									$Body->hideBlock('url_province_district_3_have_child');
								}else{
									$Body->setVariable('title_province_district_3',trim($province_district_3->title));
									$Body->showBlock('url_province_district_3_have_child');
									$Body->hideBlock('url_province_district_3_no_child');
								}
								$Body->parseList('provinces_district_3');
							}
							$Body->showBlock('provinces_d3');
						}else $Body->hideBlock('provinces_d3');*/
					$Body->parseList('provinces_3');
				}
			}
		}
	}
	//$Body->setVariable('page',$newContent);
$page->setIndex(1);
$page->setFollow(1);
$Body->stop();
$page->setBody($Body);
$page->display();

?>